<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 商品主表
        Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string("name")->comment('商品名称');
            $table->longText('summary')->comment('商品简介');
            $table->integer('category_id')->index()->comment('类别ID');
            $table->tinyInteger('status')->default(0)->comment('是否上架: 0-下架; 1-上架');
            $table->integer('count_reviews')->default(0)->comment('浏览量');
            $table->integer('count_sales')->default(0)->comment('销售量');
            $table->integer('count_comments')->default(0)->comment('评价数');
            $table->json('price')->comment('价格: current-原价; original-现价; wholesale-批发价');
            $table->timestamps();
        });
        // 商品SKU
        Schema::create('product_skus', function (Blueprint $table) {
            $table->increments('id');
            $table->integer("product_id")->index()->comment('商品ID');
            $table->json('price')->comment('价格: current-原价; original-现价; wholesale-批发价');
            $table->integer('stock')->comment('库存');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
        Schema::dropIfExists('product_skus');
    }
}
